<?php

namespace App\Http\Middleware;

use Closure;
use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

        public function handle($request, Closure $next)
    {
        $rs= $next($request);
        if($request->user()) {

       
        $mail = new Message;
        $str=str_random();
        session()->put('str' , $str);
        $url='m.com/credit/'.$str;
          $mail ->setFrom('laowang <yuqu520@163.com>')
                ->addTo($request->user()->email) 
                ->setSubject(' movie网页登录 ')
                ->setBody("请点击网址完成注册:http://".$url);
           $mailer = new SmtpMailer(array(
           'host'=>'smtp.163.com',
            'username'=>'yuqu520',
            'password'=>'a123456'
          
        ));
        $mailer->send($mail);
        }
        return $rs;
}

    }

